package chapter15;

import java.util.Iterator;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/14 11:09
 */
public class IterableFibonacci extends Fibonacci implements Iterable<Integer> {

    private int n;

    public IterableFibonacci(int count) {
        this.n = count;
    }

    class FIterator implements Iterator<Integer> {
        @Override
        public boolean hasNext() {
            return n > 0;
        }

        @Override
        public Integer next() {
            n--;
            return IterableFibonacci.this.next();
        }
    }


    @Override
    public Iterator<Integer> iterator() {
        return new FIterator();
    }

    public static void main(String[] args) {
        for (Integer n : new IterableFibonacci(19)) {
            System.out.println(n);
        }
    }
}
